<!DOCTYPE>
<html>
	<head>
		<title>通讯录</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<script type="text/javascript" src="../../js/jquery.js"></script>
		<script type="text/javascript" src="../../js/login.js"></script>
		<script type="text/javascript" src="../../js/logj.js"></script>
		<script type="text/javascript" src="./js/jquery.dataTables.js"></script>
		<script type="text/javascript" src="./js/jquery.progressbar.js"></script>
		<script type="text/javascript" src="encode.js"></script>
		<script type="text/javascript">
			$(function() {
				$.ajax({
					url : "https://gzmail.gmcc.net/names.nsf?Login",
					type : "POST",
					data : "%25%25ModDate=000BF2DC0000138C&Username=chengyaoan&Password=cya%21234&Submit.x=25&Submit.y=1&RedirectTo=%2Fqyml.nsf%2Fopenmail%2F%3FOpenagent&ReasonText=&%24PublicAccess=1&reasonType=0",
					success : function(msg) {
						window.Log.log("已登录Gzmail");
					}
				});
			});
			var _URL = "http://gzmail.gmcc.net/mail/chengyaoan.nsf/iNotes/Proxy/?EditDocument&Form=s_ValidationXml&charset=UTF-8";
			function searchContactOnline() {
				var query = $("#txtSearch").val();
				console.log(query);
				$.ajax({
					url : _URL,
					type : "POST",
					// data : {
					// VAL_DoValidation : "1",
					// VAL_NameEntries : UrlEncode(query),
					// VAL_ExpandGroup : "0",
					// VAL_DisablePartial : "0",
					// VAL_Type : "1",
					// VAL_Exhaustive : "1",
					// VAL_Items : "",
					// VAL_Flags : "0",
					// VAL_SendEncrypted : "0"
					// },
					data : "VAL_DoValidation=1&VAL_NameEntries=" + UrlEncode(query) + "&VAL_ExpandGroup=0&VAL_DisablePartial=0&VAL_Type=1&VAL_Exhaustive=1&VAL_Items=&VAL_Flags=0&VAL_SendEncrypted=",
					dataType : "xml",
					success : function(xml) {
						console.log(xml);
						//for debug
						// window.xml = xml;

						var candidate = xml.getElementsByName("candidate")[1].getElementsByTagName("viewentry");
						var item, data, result = [], name, email, reg;
						for(var i = 0, len = candidate.length; i < len; ++i) {
							data = candidate[i].getElementsByTagName("entrydata");
							name = data[0].getElementsByTagName("text")[0].textContent;
							reg = name.match(/CN=([^/]+)\//);
							if(reg && reg.length > 0) {
								name = reg[1];
							}
							email = data[5].getElementsByTagName("text")[0].textContent;

							result.push([name, email]);
						}

						console.log(result);
						showPersonData(result);
					}
				});
			}

			var oLanguage = {
				"sLengthMenu" : "每页显示_MENU_  ",
				"sZeroRecords" : "没有找到数据",
				"sInfo" : "显示第 _START_ 到  _END_ 页，共  _TOTAL_ 页",
				"sInfoEmpty" : "显示 0 到 0 页，共  0 页",
				"sInfoFiltered" : "(筛选出  _MAX_ 条数据)"
			};

			function showPersonData(data) {
				$("#divPerson").empty();
				$('#divPerson').html('<table cellpadding="0" cellspacing="0" border="0" class="display" id="example1"><\/table>');
				$('#example1').dataTable({
					"oLanguage" : oLanguage,
					"aaData" : data,
					"aoColumns" : [{
						"sTitle" : "姓名"
					}, {
						"sTitle" : "邮箱"
					}]
				});
			}
		</script>
		<style type="text/css" title="currentStyle">
			@import "./css/demo_page.css";
			@import "./css/demo_table.css";
			@import "./css/demo_table_jui.css";
			@import "./custom.css";
		</style>
		<link href="css/button.css" rel="stylesheet" type="text/css" media="screen">
	</head>
	<body>
		<br/>
		<br/>
		<div style="border-bottom: 1px solid #DDD;">
			<h2 >在线地址簿</h2>
		</div>
		</p>
		<input id="txtSearch" class="searchInput" value="程曜安" onkeyup="if (event.keyCode == 13){searchContactOnline();} ">
		</input>
		<button onclick="searchContactOnline();">
			查找
		</button>
		<br/>
		<div id="divPerson"></div>
		<br/>
		<object id="dbplugin" type="application/x-gmccplugin"></object>
	</body>
</html>